#     Xepec.ru - социальная сеть
#     Copyright (C) 2008  Fedorchenko Alexander <admin@xepec.ru>
#
#     This program is free software: you can redistribute it and/or modify
#     it under the terms of the GNU Affero General Public License as
#     published by the Free Software Foundation, either version 3 of the
#     License, or (at your option) any later version.
#
#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU Affero General Public License for more details.
#
#     You should have received a copy of the GNU Affero General Public License
#     along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#     Autor: Fedorchenko Alexander
#     Mail: <admin@xepec.ru>
#     Date: 06/02/2010
#

#require "../config.pl";
require "../core.pl";

$auth_id = do_check();
my @user_groups; #массив с группами пользователя
#my $message; # сообшение передающаееся в Xml результат (см докумантацию "XML на xepec.ru")


#print "\n \$auth_id = ".$auth_id."\n";
&get_query;

$act=$queryString{ "act" };

##################################################################
##################-Правельный вариант-############################
##################################################################
$uname_get=$queryString{ "uname" };                   ########
if (defined($uname_get))                                ####
{                                                       ####
	if ($uname_get != $auth_id)							####
	{													####
		$masha=0;										####
	}													####
	else												####
	{													####
		$masha=1;										####
	}													####
	$uname_id=$uname_get;								####
}                                                       ####
else                                                    ####
{                                                       ####
	$masha=1;											####
	print "Location: ?uname=$auth_id\n\n";				####
	exit();												####
	$uname_id=$auth_id;									####
}                                                       ####
@uname = uname_get($uname_id);                        ########
#################################################################
#################################################################
#################################################################
#используется в /litera/index.pl, /musik/index.php||pl, /groups/index.pl


if($act eq "exit")
{
		$xepec_nic_cookie = "xepec_nic 0 +3";
		$xepec_pass_cookie = "xepec_pass 0 +3";
		set_cookie($xepec_nic_cookie,$xepec_pass_cookie);
 		print "Location: $SITE_ADDR/\n\n";
}
if(!$act) {$act="show";}

if(!$auth_id) {print "Location: $SITE_ADDR/join.pl\n\n"; exit();};

###############################################################################################################################
#----------------------------------------------Вывод на экран информации------------------------------------------------------#
###############################################################################################################################
print "Content-type: text/xml; charset=utf-8\n\n";
print qq{<?xml version="1.0" encoding="UTF-8"?>
 <?xml-stylesheet type="text/xsl" href="./groups.xsl"?>
<document>
    <user>@uname['3']</user>
    <site_name>$SITE_NAME</site_name>
    <site_name2>$SITE_NAME2</site_name2>
    <title>$SITE_NAME :: @uname['1']</title>
    <version>$VERSION</version>
    <message>TRUE</message>
};

do_print_menu();



#@user_groups = show_groups($uname_id);
$gr=$queryString{ "gr" };


#$gr =1;
if ($gr==0)
{
	#############################МЕНЮ#################################################
	print qq{
	<subnav>
		<object>
			<name>Выход</name>
			<href>/groups/index.pl?uname=$auth_id&amp;act=exit\</href>
		</object>
	</subnav>
	};
	############################Контент##########################################
	print qq{
	    <content type=\"groups\">
		    <data>
			<groups id=\"@user_groups[1]\">};
			show_user_groups_names($uname_id, show_user_groups_ids($uname_id));
	print qq{
			</groups>
		    </data>
	    </content>};
}
else
{
	#############################МЕНЮ#################################################
	print qq{
	<subnav>
		<object>
			<name>К списку групп</name>
			<href>/groups/index.pl?uname=$auth_id&amp;gr=0\</href>
		</object>
		<object>
			<name>Выход</name>
			<href>/groups/index.pl?uname=$auth_id&amp;act=exit\</href>
		</object>
	</subnav>
	};
	############################Контент##########################################

	@group_arr=group_info($gr);
	@sostav_group = split / /,@group_arr[4];
	#print @sostav_group[2];
	print qq{
	    <content type=\"group\">
			<data>
				<group id=\"$gr\">};
	print qq{			
					<info>
						<autor id="@group_arr[1]">@group_arr[2]</autor>
						<name>@group_arr[3]</name>
						<sostav>};
					
							foreach (@sostav_group)
							{
								$nic = &get_nic($_);
								print "
								<item id=\"$_\" nic=\"$nic\"/>";
							}
	print qq{			
						</sostav>
						<date>@group_arr[5]</date>
						<about>@group_arr[6]</about>
						<type>@group_arr[7]</type>
						<ava src="/usr/groups/$gr/userpic-small.png"/>
					</info>};
	print qq{\n\t\t\t\t\t<comments>};
					print_comments("groups",$gr);
		print qq{\n\t\t\t\t\t</comments>};
	print qq{
				</group>
			</data>
	    </content>};
}


print qq{

</document>
};
